package com.chanjiedata.changbs.module.mine;

import android.content.Intent;
import android.graphics.Color;
import android.os.Bundle;
import android.text.Editable;
import android.text.TextWatcher;
import android.view.WindowManager;
import android.widget.EditText;
import android.widget.LinearLayout;
import android.widget.TextView;

import com.chanjiedata.changbs.R;
import com.chanjiedata.changbs.base.BaseActivity;
import com.chanjiedata.changbs.help.UserHelper;
import com.chanjiedata.changbs.utlis.StatusBarUtil;
import com.ruffian.library.widget.RCheckBox;

import java.util.ArrayList;
import java.util.List;

import butterknife.BindView;
import butterknife.ButterKnife;

/**
 * 文件名 : PayPasswordChangeActivity
 * 创建者 : MangoWang
 * 创建日期 : 2019/11/27 16:04
 * 微信 : MangoWaWang
 * 邮箱 : 763482205@qq.com
 * 描述 : TODO
 */
public class PayPasswordChangeOneActivity extends BaseActivity {

    @BindView(R.id.back_tv)
    TextView backTv;
    @BindView(R.id.tv_title)
    TextView tvTitle;
    @BindView(R.id.cb_one)
    RCheckBox cbOne;
    @BindView(R.id.cb_two)
    RCheckBox cbTwo;
    @BindView(R.id.cb_three)
    RCheckBox cbThree;
    @BindView(R.id.cb_four)
    RCheckBox cbFour;
    @BindView(R.id.cb_five)
    RCheckBox cbFive;
    @BindView(R.id.cb_six)
    RCheckBox cbSix;
    @BindView(R.id.et_input)
    EditText etInput;
    @BindView(R.id.ll_content)
    LinearLayout llContent;
    @BindView(R.id.pay_password_title)
    TextView payPasswordTitle;
    @BindView(R.id.pay_password_message)
    TextView payPasswordMessage;
    private List<RCheckBox> checkBoxList = new ArrayList<>();

    public static int PAY_STEP_ONE = 100;
    public static int PAY_STEP_TWO = 200;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activit_pay_password);
        StatusBarUtil.setStatusBarLightMode(this, Color.parseColor("#ffffff"), true);
        ButterKnife.bind(this);
        backTv.setOnClickListener(v -> finish());
        init();
    }

    private void init() {


        tvTitle.setText(getIntent().getStringExtra("activity_title"));
        payPasswordTitle.setText(getIntent().getStringExtra("title"));
        payPasswordMessage.setText(getIntent().getStringExtra("message"));

        checkBoxList.add(cbOne);
        checkBoxList.add(cbTwo);
        checkBoxList.add(cbThree);
        checkBoxList.add(cbFour);
        checkBoxList.add(cbFive);
        checkBoxList.add(cbSix);
        etInput.addTextChangedListener(new TextWatcher() {
            @Override
            public void beforeTextChanged(CharSequence s, int start, int count, int after) {

            }

            @Override
            public void onTextChanged(CharSequence s, int start, int before, int count) {


            }

            @Override
            public void afterTextChanged(Editable s) {

                for (RCheckBox rCheckBox : checkBoxList) {
                    rCheckBox.setChecked(false);
                }
                for (int i = 0; i < s.length(); i++) {
                    checkBoxList.get(i).setChecked(true);
                }
                //输入完5个验证码 自动请求验证
                if (s.length() == 6) {
                    Intent intent = new Intent(mContext, PayPasswordChangeTwoActivity.class);
                    intent.putExtra("before_password", s.toString());
                    intent.putExtra("captcha", getIntent().getStringExtra("captcha"));
                    if (UserHelper.getUser().getIs_paypwd()==0)
                    {
                        intent.putExtra("activity_title", "设置支付密码");
                        intent.putExtra("message", "第一步设置支付密码，以添加银行卡");
                        intent.putExtra("title", "设置支付密码");
                    }else
                    {
                        intent.putExtra("activity_title", "修改支付密码");
                        intent.putExtra("message", "第二步确认新的支付密码");
                        intent.putExtra("title", "修改支付密码");
                    }

                    startActivityForResult(intent, PAY_STEP_ONE);
                }
            }
        });
        etInput.setFocusable(true);
        etInput.setFocusableInTouchMode(true);
        etInput.requestFocus();
        getWindow().setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_STATE_ALWAYS_VISIBLE);
    }


    @Override
    protected void onActivityResult(int requestCode, int resultCode, Intent data) {
        super.onActivityResult(requestCode, resultCode, data);
        if (resultCode == PAY_STEP_TWO) {
            if (requestCode == PAY_STEP_ONE) {
                etInput.setText("");
            }
        }
    }

}
